package com.tony.mulitithread.utils;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

/**
 * @Author yimeng
 * @Date 2023/12/17 14:14
 * @PackageName:com.liyh.mybatis.config
 * @ClassName: SpringContextHelper
 * @Description: TODO
 * @Version 1.0
 */
@Component
public class SpringContextHelper implements ApplicationContextAware {

    private static ApplicationContext applicationContext;

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        SpringContextHelper.applicationContext = applicationContext;
    }
    //根据类获取bean
    public static Object getBean(Class<?> clazz) throws BeansException{
        return applicationContext.getBean(clazz);
    }
    //根据名称获取bean
    public static Object getBean(String name) throws BeansException{
        return applicationContext.getBean(name);
    }
}
